package edu.zut.servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "SessionServlet2", value = "/session2")
public class SessionServlet2 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        if (session.isNew()){
            System.out.println("这是新的session");
        }else {
            System.out.println("这是旧的session");
        }

        Object myName = session.getAttribute("myName");
        System.out.println("myName = " + myName);
        //移除session中的某个数据
//        session.removeAttribute("myName");
        //设置存活时间
//        session.setMaxInactiveInterval(24 * 60 * 60);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
